<template>
<div class="theme">
  <div class="theme-title">INTERFACE THEME</div>
  <div class="theme-list">
    <div class="theme-list-item"
         v-for="item in themeList"
         :key="item.value"
         :class="{ current: currentTheme === item.value }"
         @click="setTheme(item.value)">
      <img :src="item.img" alt="">
    </div>
  </div>
</div>
</template>

<script>
import themeLight from '@/assets/img/theme/theme-light.png'
import themeDark from '@/assets/img/theme/theme-dark.png'
import themeDartMenu from '@/assets/img/theme/theme-dark-menu.png'
import themeClassic from '@/assets/img/theme/theme-classic.png'

export default {
  name: "system-theme",
  data () {
    return {
      themeList: [
        {
          name: '亮色',
          img: themeLight,
          value: 'light'
        },
        {
          name: '经典',
          img: themeClassic,
          value: 'classic'
        },
        {
          name: '暗色菜单',
          img: themeDartMenu,
          value: 'dark-menu'
        },
        {
          name: '暗色',
          img: themeDark,
          value: 'dark'
        },
      ]
    }
  },
  computed: {
    currentTheme () {
      return this.$store.state.app.theme
    }
  },
  methods: {
    setTheme (theme) {
      document.documentElement.setAttribute('theme-mode', theme);
      this.$store.dispatch('setTheme', theme)
      localStorage.setItem('theme', theme)
    }
  },
  created () {
    const theme = localStorage.getItem('theme')
    this.setTheme(theme ? theme : 'classic')
  }
}
</script>

<style scoped lang="scss">
.theme {
  margin-top: 8px;
  border-top: 1px solid #00000014;
  padding: 16px 12px 8px 12px;
  &-title {
    color: #0000009C;
    font-size: 12px;
    margin-bottom: 10px;
    font-weight: bold;
  }
  &-list {
    display: flex;
    align-items: center;
    justify-content: space-between;
    &-item {
      cursor: pointer;
      flex: 1;
      flex-basis: 23%;
      background: #0000000F;
      border-radius: 4px;
      padding: 3px;
      flex-grow: 0;
      img {
        width: 100%;
        height: auto;
        display: block;
      }
    }
    .current {
      outline: 2px solid #2FB8809E;
    }
  }
}
</style>